package com.StarStudio.Controller;

import com.StarStudio.Domain.HttpStatusCode;
import com.StarStudio.Domain.MessageConstant;
import com.StarStudio.Domain.Result;
import com.StarStudio.Domain.Soil;
import com.StarStudio.Service.SoilService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/soils")
public class SoilController {

    @Autowired
    private SoilService soilService;


    @GetMapping("/{zoneId}")
    public Result getAllByZoneId(@PathVariable int zoneId){
        List<Soil> soilList = null;
        try {
            soilList = soilService.getAllByZoneId(zoneId);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(HttpStatusCode.ERROR, MessageConstant.SOIL_QUERY_FAIL);
        }
        return new Result(HttpStatusCode.SUCCESS, MessageConstant.SOIL_QUERY_SUCCESS, soilList);
    }

    @GetMapping("/one/{zoneId}")
    public Result getNewOneByZoneId(@PathVariable int zoneId){
        Soil newOneByZoneId = null;
        try {
            newOneByZoneId = soilService.getNewOneByZoneId(zoneId);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(HttpStatusCode.ERROR, MessageConstant.SOIL_QUERY_FAIL);
        }
        return new Result(HttpStatusCode.SUCCESS, MessageConstant.SOIL_QUERY_SUCCESS, newOneByZoneId);
    }


//    @PostMapping
//    public Result add(@RequestBody Soil soil) {
//        boolean code = soilService.add(soil);
//        return new Result(code);
//    }
//
//    @PutMapping
//    public Result update(@RequestBody Soil soil){
//        boolean code = soilService.update(soil);
//        return new Result(code);
//    }
//
//    @DeleteMapping("{soilId}")
//    public Result delete(@PathVariable Integer soilId){
//        boolean code = soilService.delete(soilId);
//        return new Result(code);
//    }
}
